Ext.define('PJ.view.trainingmanagement.OperatingCourseList', {
    extend: 'AM.default.DefaultList',
    alias: ['widget.pfOperatingCourseList'],
    
    initComponent: function(){
        this.columns = [{
            header: '日期',
            dataIndex: 't.speakDate',
            width: 100,
            renderer: function(value, meta, record){
                meta.tdAttr = 'data-qtip="' + value + '"';
                return value;
            }
        }, {
            header: '时间',
            dataIndex: 'c.dataCode',
            width: 70,
            renderer: function(value, meta, record){
                meta.tdAttr = 'data-qtip="' + value + '"';
                return value;
            }
        }, {
            header: '课程名',
            dataIndex: 't.courseName',
            flex:1,
            minWidth: 70,
            renderer: function(value, meta, record){
                meta.tdAttr = 'data-qtip="' + value + '"';
                return value;
            }
        }, {
            header: '课程类型',
            dataIndex: 's.dataCode',
            width: 90,
            renderer: function(value, meta, record){
                meta.tdAttr = 'data-qtip="' + value + '"';
                return value;
            }
        }, {
            header: '授课教师',
            dataIndex: 't.speaker',
            width: 80,
            renderer: function(value, meta, record){
                meta.tdAttr = 'data-qtip="' + value + '"';
                return value;
            }
        }, {
            text: '教师单位',
            dataIndex: 't.speakdept',
            width: 80,
            renderer: function(value, meta, record){
                meta.tdAttr = 'data-qtip="' + value + '"';
                return value;
            }
        }, {
            header: '职务职称',
            dataIndex: 't.speakDuty',
            width: 70,
            renderer: function(value, meta, record){
                meta.tdAttr = 'data-qtip="' + value + '"';
                return value;
            }
        }];
        this.store = Ext.create('PJ.'+ prototype +'.trainingmanagement.OperatingCourseList', {
            isLoad: false
        });
        this.loadType = gj_onlineLearning_constant.loadType;
        this.callParent(arguments);
    },

    //更新
    onUpdateClick: function(button){
        var me = this;
        var records = me.getSelectionModel().getSelection();
        win = Ext.create('PJ.view.trainingmanagement.OperatingCourseEdit',{
        	title: "更新课程",
        	grid: me
        }).show();
		var actionName = "load";//默认使用非JSONP的加载方法名“load”
        if(gj_onlineLearning_constant.loadType=="jsonp") {//根据模块的全局变量设置是否使用JSONP的方式请求数据
        	actionName= "loadJsonp";
        }
        win.down('form').getForm().doAction(actionName,{//使用doAction(action,{options})；方式加载数据
        url: me.store.preUpdateUrl,
            params: {
            	classCourseId: records[0].get("classCourseId")//培训班ID
			},
            success:function(form,action){}
        });
    },
    // 删除
    onDeleteClick: function(button){
        var me = this;
        var records = this.getSelectionModel().getSelection();
        Ext.Msg.confirm({
            title: '提示',
            msg: '您确定要删除这些信息吗?',
            buttons: Ext.Msg.OKCANCEL,
            fn: function(id){
                if (id == 'ok') {
                    var courseIds = new Array();
                    Ext.Array.each(records, function(name, index){
                    	courseIds.push(name.get("classCourseId"));
                    });
                    if(gj_onlineLearning_constant.loadType == "jsonp"){
                    	var store1 = Ext.create('AM.default.jsonp.DefaultAjaxStore',{
                    		loadType: gj_onlineLearning_constant.loadType,
                    		url: me.getStore().deleteUrl,
                    		extraParams: {
                    			ids: courseIds
                    		}
                    	});
                    	store1.load(function(rec, operation, success){
                    		var msg = success == true ? '删除成功！' : operation.error;
                			Orchid.alert('消息', msg, function(){
            					var store = me.getStore();
            					store.load();
            				});
                    	});
                    }else if(gj_onlineLearning_constant.loadType == "ajax"){
                    	Ext.Ajax.request({
                    		url: me.getStore().deleteUrl,
                    		params: {
                    			ids: courseIds
                    		},
                    		success: function(response){
                    			var data = response.responseText;
                    			var json = Ext.decode(data, true);
                        		var msg = json.success == true ? '删除成功！' : json.msg;
                    			Orchid.alert('消息', msg, function(){
                					var store = me.getStore();
                					store.load();
                				});
                    		}
                    	});
                    }
                }
                else {
                    return;
                }
            }
        });
    },
    //批量导入
    onImpotrClick: function(){
        var me = this;
		Ext.create("PJ.view.trainingmanagement.CourseInfo", {
			title: "课程导入",
			autoHeight: true,
			width: 460,
			grid: me,
			winUp: me.up('window'),
			classId: me.up('window').classId//班级Id
		}).show();
    },
  
    //下载模板
    onTemplateClick: function(){
        var me = this;
        var atag = Ext.get("exportResume");
        atag.set({
            "href": me.store.templateUrl + "?attachmentID=1"
        });
        atag.dom.click();
    },
    listeners: {
        viewready: function(){
            this.addDocked([{
                xtype: 'toolbar',
                dock: 'top',
                displayInfo: true,
                items: [this.updateButton, "-",this.deleteButton, '-', {
                    text: '批量导入',
                    iconCls: 'updateIco',
                    itemId: this.oldId + "Import",
                    scope: this,
                    handler: this.onImpotrClick
                },  '-', {
                    text: '下载导入模板',
                    iconCls: 'templateIco',
                    itemId: this.oldId + "Template",
                    scope: this,
                    handler: this.onTemplateClick
                },"->", "->", this.countSelectPanel]
            }]);
            var me = this;
            // 触发权限过滤事件
            me.fireEvent("permission", this);
            var params = me.store.proxy.extraParams;
            var newParams = {
            		searchClassId: me.up('window').classId
            };
            Ext.apply(params, newParams);
            this.store.isLoad = true;
            this.store.load();
        }
    }
});
